from rest_framework import serializers

from base.models import User, Feedback, LocationHistory, UserInfo


class RegisterSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = "__all__"

class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['username','email','phone',]
class LoginSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = "__all__"

class FeedbackSerializer(serializers.ModelSerializer):
    class Meta:
        model = Feedback
        fields = '__all__'

class LocationHistorySerializer(serializers.ModelSerializer):
    submit_time = serializers.SerializerMethodField()
    class Meta:
        model = LocationHistory
        fields = "__all__"
    def get_submit_time(self, obj):
        return obj.submit_time.strftime('%Y-%m-%d %H:%M')

class SearchUserInfoSerializer(serializers.ModelSerializer):
    username=UserSerializer(read_only=True)
    class Meta:
        model = UserInfo
        fields = ['nickName','age','sex','city','username']

class UserInfoSerializer(serializers.ModelSerializer):
    class Meta:
        model = UserInfo
        fields = ['nickName','age','sex','city','username']